<template>
  <div class="order-container">
    <el-form ref="form" v-model="form" label-width="80px" inline>
      <el-form-item label="用户昵称">
        <el-input v-model="form.searchUserName" style="width: 170px"></el-input>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          type="date"
          placeholder="起始日期"
          v-model="form.startDate"
          value-format="yyyy-MM-dd"
          style="width: 150px"
        ></el-date-picker>
        <span style="margin: 0 5px">-</span>
        <el-date-picker
          placeholder="截止日期"
          v-model="form.endDate"
          value-format="yyyy-MM-dd"
          style="width: 150px"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click.prevent="searchInfo()">搜索</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
    <template>
  <div v-for="order in pageInfo.list" :key="order.id">
    <p>
      <span>订单号：{{ order.serialNumber }}</span>
      <span>创建时间：{{ order.createTime }}</span>
    </p>
    <p>
      <span>用户名：{{ order.loginName }}</span>
      <span>用户地址：{{ order.userAddress }}</span>
      <span>订单状态：{{ getStatus(order.status) }}</span>
    </p>
    <el-collapse v-model="activeNames">
      <el-collapse-item :name="order.id">
        <template slot="title">
          <span>订单明细</span>
        </template>
        <el-table :data="order.orderDetails" border style="width: 100%">
          <el-table-column label="序号" width="50">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column prop="productName" label="商品名称" width="100"></el-table-column>
          <el-table-column prop="quantity" label="数量" width="80"></el-table-column>
          <el-table-column prop="cost" label="价格(元)" width="150"></el-table-column>
        </el-table>
      </el-collapse-item>
    </el-collapse>
    <p>
      <span>总消费(元)：{{ order.cost }}</span>
    </p>
    <hr>
  </div>
</template>
    <div class="block">
      <el-pagination
        @size-change="changePageSize"
        @current-change="changePageNum"
        :current-page="form.pageNum"
        :page-sizes="[5, 10]"
        :page-size="form.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageInfo.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "myOrderPage",
  data() {
    return {
      pageInfo: {},
      form: {
        searchUserName: "",
        startDate: "",
        endDate: "",
        pageNum: 1,
        pageSize: 5,
      },
      isAll: "",
    };
  },
  created() {
    if (
      this.$router.currentRoute.path == "/managerIndex/manageOrder/allOrder"
    ) {
      this.isAll = 1;
    }
  },
  methods: {
    searchInfo() {
      this.$axios
        .get("api/order/page", {
          params: {
            isAll: this.isAll,
            startDate: this.form.startDate,
            endDate: this.form.endDate,
            pageNum: this.form.pageNum,
            pageSize: this.form.pageSize,
          },
        })
        .then((response) => {
          this.pageInfo = response.data.pageInfo;
          console.log(this.pageInfo.list);
        })
        .catch((error) => {
          console.log(error);
        });
    },
    getStatus(status) {
      if (status == 0) {
        return "待支付";
      } else if (status == 1) {
        return "已支付";
      } else if (status == 2) {
        return "已关闭";
      } else if (status == 3) {
        return "已退款";
      }
    },
    changePageNum(newPageNum) {
      this.form.pageNum = newPageNum;
      this.searchInfo();
    },
    changePageSize(newPageSize) {
      this.form.pageSize = newPageSize;
      this.searchInfo();
    },
    delUser(id) {
      console.log(id);
      // if (confirm("确认删除该用户吗？")) {
      //   this.$axios
      //     .get(`api/user/del/${id}`)
      //     .then((response) => {
      //       if (response.data.delStatus) {
      //         alert("删除成功");
      //         this.searchInfo();
      //       }
      //     })
      //     .catch((error) => {
      //       this.$message.error("删除失败");
      //       console.error(error);
      //     });
      // }
    },
  },
  mounted() {
    this.searchInfo();
  },
};
</script>

<style scoped>

</style>
